<?php
class IndexAction extends AdminAction{
	public function index(){
		$this->display();   
		
		
	}
	public function main(){
		$this->display();
	}
	/**
	 * 加载功能菜单（左侧菜单）
	 */
	public function menu(){
		// 加载功能菜单
	    $list = array();
		$id = I('get.id','','intval');
		$pModel = M('AdminMenu');
		$sModel = M('AdminPriv');
		if(!empty($id)){
    		$parentlist = $pModel->where(array('parentid'=>$id,'status'=>'1'))->order('`sort` desc')->select();
    		if (!empty($parentlist)) {
    			if(session('dis_role')==1){
    				$list = $parentlist;
    			}else{
    				$sonlist = $sModel->where(array('role_id'=>session('dis_role')))->select();
    				foreach ($parentlist as $p){
    					foreach ($sonlist as $s){
    						if(($p['m']==$s['m'])&&($p['c']==$s['c'])&&($p['a']==$s['a'])){
    							$list[] = array('id'=>$p['id'],'name'=>$p['name'],'m'=>$p['m'],'c'=>$p['c'],'a'=>$p['a']);
    						}
    					}
    				}
    			}
    		}
		}
		$this->assign('list',$list);
		$this->display();
	}
	/**
	 * 上部显示
	 */
	public function top(){
		$js_file = Resource::getStatic('cookie','js');
		$change = '';
		if (isset($_COOKIE['style']) && ! empty($_COOKIE['style'])) {
			$change = Resource::getStatic($_COOKIE['style'],'css');
        }
        $Model = M('AdminMenu');
        $parentlist = $Model->field('id,name,m,c,a')->where(array('parentid'=>0,'status'=>'1'))->order('`sort` desc')->select();
        if(session('dis_role')=='1'){
        	$list = $parentlist;
        }else{
        	$privModel = M('AdminPriv');
        	$privlist = $privModel->where(array('role_id'=>session('dis_role')))->select();
        	if(empty($parentlist)){
        		$parentlist = array();
        	}
        	if(empty($privlist)){
        		$privlist = array();
        	}
        	$list = array();
        	foreach ($parentlist as $p){
        		foreach ($privlist as $s){
        			if(($p['m']==$s['m'])&&($p['c']==$s['c'])&&($p['a']==$s['a'])){
        				$list[] = array('id'=>$p['id'],'name'=>$p['name'],'m'=>$p['m'],'c'=>$p['c'],'a'=>$p['a']);
        			}
        		}
        	}
        }
        
        $this->assign('cookie',$js_file);
        $this->assign('change',$change);
        $this->assign('list',$list);
		$this->display();
	}
	
	/**
	 * 退出登录
	 */
	public function logout()
	{
		unset($_SESSION);
		session('[destroy]');
		$this->assign('jumpUrl', '/Admin/Public/login');
		$this->success('安全退出');
	}
	public function _empty($name){
            $this->display('Public:notfound');
    }
}